package com.ruoyi.sso.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.sso.domain.SsoWyUrl;
import com.ruoyi.sso.service.ISsoWyUrlService;

/**
 * 转发地址Controller
 * 
 * @author zsj
 * @date 2020-01-07
 */
@Controller
@RequestMapping("/sso/wyUrl")
public class SsoWyUrlController extends BaseController
{
    private String prefix = "sso/wyUrl";

    @Autowired
    private ISsoWyUrlService ssoWyUrlService;

    @RequiresPermissions("sso:wyUrl:view")
    @GetMapping()
    public String wyUrl()
    {
        return prefix + "/wyUrl";
    }

    /**
     * 查询转发地址列表
     */
    @RequiresPermissions("sso:wyUrl:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SsoWyUrl ssoWyUrl)
    {
        startPage();
        List<SsoWyUrl> list = ssoWyUrlService.selectSsoWyUrlList(ssoWyUrl);
        return getDataTable(list);
    }

    /**
     * 导出转发地址列表
     */
    @RequiresPermissions("sso:wyUrl:export")
    @Log(title = "转发地址", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SsoWyUrl ssoWyUrl)
    {
        List<SsoWyUrl> list = ssoWyUrlService.selectSsoWyUrlList(ssoWyUrl);
        ExcelUtil<SsoWyUrl> util = new ExcelUtil<SsoWyUrl>(SsoWyUrl.class);
        return util.exportExcel(list, "wyUrl");
    }

    /**
     * 新增转发地址
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存转发地址
     */
    @RequiresPermissions("sso:wyUrl:add")
    @Log(title = "转发地址", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SsoWyUrl ssoWyUrl)
    {
        return toAjax(ssoWyUrlService.insertSsoWyUrl(ssoWyUrl));
    }

    /**
     * 修改转发地址
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        SsoWyUrl ssoWyUrl = ssoWyUrlService.selectSsoWyUrlById(id);
        mmap.put("ssoWyUrl", ssoWyUrl);
        return prefix + "/edit";
    }

    /**
     * 修改保存转发地址
     */
    @RequiresPermissions("sso:wyUrl:edit")
    @Log(title = "转发地址", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SsoWyUrl ssoWyUrl)
    {
        return toAjax(ssoWyUrlService.updateSsoWyUrl(ssoWyUrl));
    }

    /**
     * 删除转发地址
     */
    @RequiresPermissions("sso:wyUrl:remove")
    @Log(title = "转发地址", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ssoWyUrlService.deleteSsoWyUrlByIds(ids));
    }
    
    /**
     * 对外接口，列表
     * @param ssoWyUrl
     * @return
     */
    @GetMapping("/apiList")
    @ResponseBody
    public List<SsoWyUrl> apiList(SsoWyUrl ssoWyUrl)
    {
        List<SsoWyUrl> list = ssoWyUrlService.selectSsoWyUrlList(ssoWyUrl);
        return list;
    }
}
